<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
        <link rel="stylesheet" href="${pageContext.request.contextPath}/css/buygame.css">
        <script src="${pageContext.request.contextPath}/js/buygame.js"></script>
        <script>
            var flag = '${flag}'
			if (flag == '1') {
				alert('购买成功');
			} else if (flag == '2') {
				alert('购买失败');
			}
        </script>
        <div class="buygame">
            <h1>游戏列表</h1>
            <div class="search">
                <form action="" method="post">
                    <input type="text" class="text" placeholder="${query_tip}"><input type="button" value="搜索"
                        class="button">
                </form>
            </div>
            <table>
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>游戏名</th>
                        <th>发行商</th>
                        <th>发行日期</th>
                        <th>简介</th>
                        <th>游戏类型</th>
                        <th>管理</th>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${games}" var="game" varStatus="stat">
                        <tr>
                            <td>${stat.index+1+page}</td>
                            <td>${game.gamename}</td>
                            <td>${game.publisher}</td>
                            <td>${game.adddate}</td>
                            <td>${game.introduce}</td>
                            <td>${game.type}</td>
                            <td>
                                <input type="button" value="${game.buystate==1?'已买入':'买入'}"
                                    onclick="buy('${gengraluser.id}','${game.id}','${game.buystate}')">
                            </td>
                            <script>
                                function buy(userid, gameid,state) {
                                    if(state==0){
                                        window.location='change?action=buy&userid='+userid+'&gameid='+gameid;
                                    }else{
                                        alert('已购买');
                                    }
                                }
                            </script>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
            <c:if test="${query_tip=='请输入游戏名...'}">
                <div class="page">
                    <input type="button" value="首页" class="start_page">
                    <input type="button" value="上一页" class="prev_page"> <input type="button" value="下一页"
                        class="next_page"> <input type="button" value="尾页" class="end_page">
                </div>
                <script>
                    //页面跳转
                    var page = parseInt('${page}');
                    var total = parseInt('${totalPage}');
                    var start = $('.buygame .page .start_page');
                    var up = $('.buygame .page .prev_page');
                    var down = $('.buygame .page .next_page');
                    var end = $('.buygame .page .end_page');

                    start.click(function () {
                        page = 0;
                        window.location.href = 'buygame?page=' + page;
                    })

                    up.click(function () {
                        page = page - 8;
                        if (page < 0) {
                            page = 0;
                        } else {
                            window.location.href = 'buygame?page=' + page;
                        }
                    });

                    down.click(function () {
                        page = page + 8;
                        if (page > total * 8 - 8) {
                            page = total * 8 - 8;
                        } else {
                            window.location.href = 'buygame?page=' + page;
                        }
                    });

                    end.click(function () {
                        page = page = total * 8 - 8;
                        window.location.href = 'buygame?page=' + page;
                    });
                </script>
            </c:if>
        </div>
        </div>

        <!-- 页面底部部分 -->
        <div class="footer">
            <a href=""><span>©:关于我们</span></a>
        </div>


        </div>
        </body>

        </html>